﻿/// <reference path="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\MicrosoftAjax.js" />
/// <reference path="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\SP.debug.js" />
/// <reference path="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\SP.Ribbon.debug.js" />
/// <reference path="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\SP.Core.debug.js" />
Type.registerNamespace('RibbonCustomization');

RibbonCustomization.SampleWebPartComponent = function (id) {
    RibbonCustomization.SampleWebPartComponent.initializeBase(this);
    this._id = id;
}

RibbonCustomization.SampleWebPartComponent.prototype =
{
    _id: null,

    init: function () {
    },

    isFocusable: function () {
        return true;
    },

    receiveFocus: function () {
        return true;
    },

    yieldFocus: function () {
        return true;
    },

    getFocusedCommands: function () {
        var commands = new Array();
        Array.add(commands, 'Ribbon.MyContextualGroup.WebPartContextualTab.DemoGroup');
        Array.add(commands, 'Ribbon.MyContextualGroup.WebPartContextualTab.DemoGroup.MyFirstButton');
        return commands;
    },

    getGlobalCommands: function () {
        var commands = new Array();
        Array.add(commands, 'Ribbon.MyContextualGroup');
        Array.add(commands, 'Ribbon.MyContextualGroup.WebPartContextualTab');
        Array.add(commands, 'Ribbon.MyContextualGroup.WebPartContextualTab.DemoGroup');
        Array.add(commands, 'Ribbon.MyContextualGroup.WebPartContextualTab.DemoGroup.MyFirstButton');
        return commands;
    },

    canHandleCommand: function (commandId) {
        if (commandId == 'Ribbon.MyContextualGroup' ||
            commandId == 'Ribbon.MyContextualGroup.WebPartContextualTab' ||
            commandId == 'Ribbon.MyContextualGroup.WebPartContextualTab.DemoGroup' ||
            commandId == 'Ribbon.MyContextualGroup.WebPartContextualTab.DemoGroup.MyFirstButton') {
            return SP.Ribbon.WebPartComponent.get_pageComponentIdOfActiveWebPart() == this._id;
        }
        return false;
    },

    handleCommand: function (commandId, properties, sequence) {
        if (SP.Ribbon.WebPartComponent.get_pageComponentIdOfActiveWebPart() == this._id) {
            var statusId = SP.UI.Status.addStatus("Web Part", this._id);
            SP.UI.Status.setStatusPriColor(statusId, 'green');
            return true;
        }
        return false;
    }
}

RibbonCustomization.SampleWebPartComponent.registerClass('RibbonCustomization.SampleWebPartComponent', SP.Ribbon.WebPartComponent);
if (typeof (Sys) != "undefined" && Sys && Sys.Application) {
    Sys.Application.notifyScriptLoaded();
}
NotifyScriptLoadedAndExecuteWaitingJobs("SampleWebPartComponent.js");